package com.shenghuai.bclient.stores.util;


/**
 * Created by liulei
 * 2020/1/15 11:19
 * {描述这个类功能}
 */
public class SafeUtils {

    public interface Func1<R> {
        R apply();
    }

    public static <R> R get(Func1<R> func1, R defaultVal) {
        try {
            return func1.apply();
        } catch (Throwable ignored) {
        }
        return defaultVal;
    }

    public static void safeRun(Runnable mRunnable, boolean printError) {
        try {
            mRunnable.run();
        } catch (Throwable ex) {
            if (printError)
                ex.printStackTrace();
        }
    }

    public static void safeRun(Runnable mRunnable) {
        safeRun(mRunnable, true);
    }
}
